package td3.model;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;

import javax.swing.tree.DefaultMutableTreeNode;

public class ContactNodeTransferable implements Transferable {

	private DefaultMutableTreeNode node;

	protected static final DataFlavor nodeFlavor = new DataFlavor(
			DataFlavor.javaJVMLocalObjectMimeType, "ContactNode");

	public ContactNodeTransferable(DefaultMutableTreeNode node) {
		super();
		this.node = node;
	}

	public static DataFlavor getNodeFlavor() {
		return nodeFlavor;
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		if (flavor == nodeFlavor)
			return node;
		return null;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		DataFlavor[] result = { nodeFlavor };
		return result;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return Arrays.asList(getTransferDataFlavors()).contains(flavor);
	}

}
